(function(window){

	if(!window.console) window.console = {log:function(p){}, info:function(){}, warn:function(){}};
		
	var PlatteCarreeCoords = new function(){

		PlatteCarreeCoords.COORDS_CLICK = "COORDS_CLICK";

		PlatteCarreeCoords.prototype.image;
		PlatteCarreeCoords.prototype.div;
		var self;

		function PlatteCarreeCoords(container, id){ /*CONSTRUCTOR*/
			self = this;
			this.div = document.createElement("DIV");
			this.image = new Image();
			//this.div.style.width = "auto";
			//this.div.style.height = "auto";
			this.image.id = id;
			container.appendChild(this.image);
			//this.div.appendChild(this.image);
			this.image.onmousemove = onMouseMoveHandler;
			this.image.onclick = onClickHandler;
			this.image.onload = imageLoadComplete;
		}
		function imageLoadComplete(event){
			console.log(event.target.width);
			
		}
		function onClickHandler(event){
			var percX = event.offsetX/event.target.width;
			var percY = event.offsetY/event.target.height;
			var lon = 360*percX-180;
			var lat = -180*percY+90;
			EventCentral.getInstance().dispatchEvent({type:PlatteCarreeCoords.COORDS_CLICK, target:this, lat:lat, lon:lon})
			console.log(lat+" - "+lon);
		}
		function onMouseMoveHandler(event){
			//console.log(event.offsetX/event.target.width);
			//self.image.width = window.innerWidth;
			//self.image.height = window.innerWidth*0.5;
		}
		PlatteCarreeCoords.prototype.setImage = function(i){
			this.image.src = i;
		}
		return PlatteCarreeCoords;
	}
	if(!window.PlatteCarreeCoords) window.PlatteCarreeCoords = PlatteCarreeCoords;
}(window));